import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

//import loginPage from '../views/login'

const routes = [
  { path: '/', redirect: '/login' },
  { 
    path: '/index', 
    component:() => import('../views/index'),
    redirect: '/index/banners',
    meta: { title: '首页' },
    children: [
      { 
        path: 'banners',
        meta: { title: '轮播图管理' }, 
        component:() => import('../views/shouye/banner'),
        beforeEnter: (to, from,next) => {
          // reject the navigation
          console.log('独享守卫')
          next()
        }
      },
      { path: 'category',meta: { title: '分类管理' }, component:() => import('../views/shouye/category') },
      { path: 'recomend',meta: { title: '为您推荐管理' }, component:() => import('../views/shouye/recomend') },
      {path: 'fenlei', meta:{title:'分类管理'}, component:() =>import('../views/product/fenlei')},
        {path: 'pinpai', meta:{title:'品牌管理'}, component:() =>import('../views/product/pinpai')},
        {path: 'shangpin', meta:{title:'商品管理'}, component:() =>import('../views/product/shangpin')},
        {path: 'xinwen', meta:{title:'新闻管理'}, component:() =>import('../views/xinwen/xinwen')}
    ]
  },
  { path: '/login', component:() => import('../views/login') }
]

const router = new VueRouter({
  routes // `routes: routes` 的缩写
})

router.beforeEach((to, from,next) => {
  // ...
  // 返回 false 以取消导航
  //console.log(to,from)
  next()
  //return true
})

export default router